<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>子组件向父组件传递数据</title>
	<script src="vue.js"></script>
</head>
<body>
<div id="app">
    <parent></parent>
</div>  
<script>
var childNode = Vue.extend({
    template: '<div><button @click="change">单击给父组件传值</button></div>',
    methods:{
        change: function(){
            this.$emit('posttoparent',10)
        }
    }
});
var parentNode = Vue.extend({
    template: '<div><child v-on:posttoparent="getfromchild"></child>子组件传递给父组件的值为：{{ datafromchild }}</div>',
    data(){
        return{
            datafromchild:''
        }
    },
    components:{
        'child':childNode
    },
    methods: {
        getfromchild: function(val){
            this.datafromchild = val
        }
    }
});
// 创建根实例
var vm=new Vue({
    el: '#app',
    components: {
      'parent': parentNode
    }
  })
 </script>
</body>
</html>